package com.fly.data.jdbc.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fly.data.jdbc.service.TaskService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "异步接口演示")
@RestController
@RequestMapping("/tasks")
public class TaskController
{
    @Autowired
    private TaskService taskService;
    
    @ApiOperation("启动任务，启用事务")
    @GetMapping("/start")
    public String startTasks()
    {
        for (int i = 0; i < 5; i++)
        {
            taskService.asyncTask1("Task-" + i);
        }
        return "已启动5个异步任务";
    }
    
    @ApiOperation("启动任务，不启用事务")
    @GetMapping("/start2")
    public String startTask2()
    {
        for (int i = 0; i < 5; i++)
        {
            taskService.asyncTask2("Task-" + i);
        }
        return "已启动5个异步任务";
    }
    
    @ApiOperation("query")
    @GetMapping("/query")
    public List<Map<String, Object>> query()
    {
        return taskService.query();
    }
}